/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package gitbox;
import java.sql.*;

/**
 *
 * @author Maulnick
 */
public class Connections {

    @SuppressWarnings("OverridableMethodCallInConstructor")
    public Connections()
    {
        try
        {
            Class.forName("com.mysql.jdbc.Driver");
            seturl("jdbc:mysql://localhost:3306/");
            setdb("gitbox");
            driver = "com.mysql.jdbc.Driver";
            setuser("root");
            setpass("");
            setcon(geturl(),getdb(),getuser(),getpass());
        } 
        catch (SQLException e)
        {
            //System.out.println("SQL Exception: "+ e.toString());
            //JOptionPane.showMessageDialog(SFA   , "SQL Exception: " + e.toString());
        } 
        catch (ClassNotFoundException cE)
        {
            //System.out.println("Class Not Found Exception: "+ cE.toString());
            //JOptionPane.showMessageDialog(SFA, "Class Not Found Exception " + cE.toString());
        }

    }
    public void disconnect(){
       try{
           con.close();
        }catch(SQLException s){
           //JOptionPane.showMessageDialog(SFA, "Failed to Disconnect");
            //System.out.println("tes");
        }
    }

    public Connection getconnection(){
        return con;
    }
    public String geturl(){
        return url;
    }
    public String getdb(){
        return db;
    }
    public String getuser(){
        return user;
    }
    public String getpass(){
        return pass;
    }
    public void seturl(String ur){
        url = ur;
    }
    public void setdb(String dbase){
        db = dbase;
    }
    public void setuser(String usr){
        user = usr;
    }
    public void setpass(String pwd){
        pass = pwd;
    }
    public void setcon(String url, String db, String user, String pass) throws SQLException{
        con = DriverManager.getConnection(url + db, user , pass);
    }
    /**
     * attribut
     */
    private Connection con;
    private String url;
    private String db;
    private String driver;
    private String user;
    private String pass;

}
